/**
 * 회원관리에서 쓰는 JS
 */

/**
 * 유료개발자회원 상세페이지
 * @param mbrNo
 * @return
 */
function viewDevMember(insdSellermbrNo, topCode, leftCode) {
	var url = env.contextPath + "/memberDev/memberView.omp?mbrNo=" + insdSellermbrNo + "&insdSellermbrNo=" + insdSellermbrNo + "&topCode=" + topCode + "&leftCode=" + leftCode;
	location.href = url;
}

/**
 * 자주 쓰는 페이지 이동.
 * @param page
 * @return
 */
function gotoPage(page) {
	var url = "";
	/*
	 * 가입신청관리
	 */
	if (page == 'REGIST') url = env.contextPath + "/memberDev/memberJoin.omp?scale=10&topCode=M001&leftCode=M001002002";
	/*
	 * 회원정보관리
	 */
	else if (page == "TURN") url = env.contextPath + "/memberDev/membership.omp?scale=10&topCode=M001&leftCode=M001002003";
	/*
	 * 탈퇴회원관리
	 */
	else if (page == "LEAVE") url = env.contextPath + "/memberDev/memberLeave.omp?scale=10&topCode=M001&leftCode=M001002004";
	
	location.href= url;
}

/**
 * 연회비 납입 내역 팝업
 * @param mbrNo
 * @param mbrId
 * @return
 */
function popPayHist(mbrNo, mbrId) {
	var url = env.contextPath + "/memberDev/popPayHist.omp?hist.scale=5&mbrNo=" + mbrNo + "&mbrId=" + encodeURIComponent(mbrId);
	openCenteredWindow(url, 650, 500, 'yes', 'popPayHist');
}

/**
 * 탈퇴사유 팝업
 * @param mbrNo
 * @param mbrId
 * @return
 */
function popLeave(mbrNo, mbrId) {
	var url = env.contextPath + "/memberDev/popLeaveReason.omp?mbrNo=" + mbrNo + "&mbrId=" + encodeURIComponent(mbrId);
	openCenteredWindow(url, 420, 200, 'yes', 'popLeave');
}

/**
 * 전환신청서 팝업
 * @param mbrNo
 * @param mbrId
 * @param turnStat
 * @return
 */
function popTurnReq(insdSellermbrNo, sellermbrId) {
	var url = env.contextPath + "/memberDev/popTurnReq.omp?insdSellermbrNo=" + insdSellermbrNo + "&sellermbrId=" + sellermbrId;
	openCenteredWindow(url, 820, 500, 'yes', 'popTurnReq');
}

/**
 * 가입신청 승인/거절/가입신청정보 삭제
 * @param mbrNo
 * @param mbrCatCd
 * @param transTpCd
 * @param transNo
 * @param mode
 * @return
 */
function registAuth(mbrNo, mbrCatCd, transTpCd, transNo, mode) {
	if(mode == 'N'){
		popRegistAuthRejectReg(mbrNo, mbrCatCd, transTpCd, transNo);
		return;
	}
	$.postJSON(
		env.contextPath + "/memberDev/ajaxRegistAuth.omp",
		{ mbrNo: mbrNo, mbrCatCd: mbrCatCd, transTpCd: transTpCd, transNo: transNo, mode: mode },
		function(data) {
			if (data.resultCode == 1) {
				var text = "승인완료";
				var returnUrl = env.contextPath + "/memberDev/memberView.omp?mbrNo="+mbrNo;
				if (mode == 'N') {
					text = "승인거절"; 
				} else if (mode == 'D') {
					text = "가입신청정보가 삭제";
					returnUrl = env.contextPath + "/memberDev/memberJoin.omp?scale=10";
				}
				alert(text +" 되었습니다.");
				location.href = returnUrl;
			} else {
				alert(data.errorMsg);
			}
		}
	);
}

/**
 * 전환신청 승인/거절
 * @param mbrNo
 * @param mode
 * @return
 */
function turnAuth(insdSellermbrNo, mode, multimdaAuthDataList) {
	if(mode == 'N') {
		popTurnAuthRejectReg(mbrNo);
		return;
	}
	
	$.postJSON(
		env.contextPath + "/memberDev/ajaxTurnAuth.omp",
		{ insdSellermbrNo: insdSellermbrNo, mode: mode, multimdaAuthDataList: JSON.stringify(multimdaAuthDataList) },
		function(data) {
			if (data.resultCode == 1) {
				var text = "승인완료";
				var returnUrl = env.contextPath + "/memberDev/memberView.omp?mbrNo=" + insdSellermbrNo + "&insdSellermbrNo=" + insdSellermbrNo;
				if (mode == 'N') {
					text = "승인거절"; 
				} 
				alert(text +" 되었습니다.");
				location.href = returnUrl;
			} else {
				alert(data.errorMsg);
			}
		}
	);
}

function popTurnAuthRejectReg(insdSellermbrNo){
	var url = env.contextPath + "/memberDev/popTurnAuthRejectReg.omp?insdSellermbrNo=" + insdSellermbrNo;
	openCenteredWindow(url, 500, 180, 'yes', 'popTurnAuthRejectReg');	
}

function popRegistAuthRejectReg(mbrNo, mbrCatCd, transTpCd, transNo){
	var url = env.contextPath + "/memberDev/popRegistAuthRejectReg.omp?mbrNo=" + mbrNo+"&mbrCatCd="+mbrCatCd+"&transTpCd="+transTpCd+"&transNo="+transNo;
	openCenteredWindow(url, 500, 180, 'yes', 'popTurnAuthRejectReg');	
}

/**
 * 탈퇴완료처리
 * @param mbrNo
 * @return
 */
function leaveAuth(insdSellermbrNo) {
	$.postJSON(
			env.contextPath + "/memberDev/ajaxLeaveAuth.omp",
			{ insdSellermbrNo: insdSellermbrNo },
			function(data) {
				if (data.resultCode == 1) {
					var returnUrl = env.contextPath + "/memberDev/memberLeave.omp?scale=10&topCode=M001&leftCode=M001002004";
					alert("탈퇴완료 되었습니다.");
					location.href = returnUrl;
				} else {
					alert(data.errorMsg);
				}
			}
		);
}

/**
 * 사업자서류 수정
 * @param type
 * @return
 */
function modifyDoc(type) {
	var docCount = 0;
	if ($("input:file").length == 0) {
		alert("수정할 사업자 등록서류가 없습니다.");
		return;
	} else {
		
		$("input:file").each(function () {
			if('bp' != type){ //개발자 회원인 경우 처리 (bp 회원은 checkFile로 처리)
		        if ($(this).val() != "") {
		        	docCount++;
		        	var docNum = $(this).attr("id").substring(6);
		        	$("#fileName0"+docNum).val($(this).val());
		        }
		        if (docCount == 0) {
					alert("수정할 사업자 등록서류가 없습니다.");
					return;
				}
			}
		});
	}
	if (confirm("정말 수정하시겠습니까?")) {
		$("#memberDocModify").submit();
	}
}

function checkFile(uploadImgObj){
    var enableUploadFileExt = 'zip';
    
    var uploadImgObjName = uploadImgObj.value;
    var startPoint = 0;
    var isFile = false;
    
    // File 체크확인
    if(uploadImgObj.value == ""){
        return;
    }
    
    // 파일 확장자 체크
    for(var i=uploadImgObjName.length-1; i>=0; i--) {
        if(uploadImgObjName.charAt(i) == ".") {
            startPoint = i;
            break;
        }
    }
    
    var uploadImgObjExt = uploadImgObjName.substring(startPoint+1,uploadImgObjName.length);
    if(uploadImgObjExt.toLowerCase() == enableUploadFileExt) isFile = true;

    var filename = uploadImgObjName.substring(uploadImgObjName.lastIndexOf('\\') + 1);

    // 첨부 불가능한 파일일 경우
    if(!isFile){
        alert(enableUploadFileExt +"파일만 업로드 가능합니다.");
        isFile = false;
        return;
    }else{
        isFile = true;
        $("#fileNameBP").val(filename);
    }

    return isFile;
}
